<?php
/**
 *User :门前一棵柿子树
 *Date:2024/4/12
 *Email:785313152@qq.com
 */

namespace app\admin\controller;

use app\admin\model\ProposeClassify;
use app\common\controller\AdminBase;

class Proposeclass extends AdminBase
{
    public function index(){
        return $this->fetch();
    }
    public function getLists()
    {
        if($this->request->isAjax()) {
            $m = new ProposeClassify();
            return $m->getLists();
        }
    }
    public function edit()
    {
        $rows = ProposeClassify::get(input('id/d'));
        session('redirect_url',$_SERVER['HTTP_REFERER']);   //记住编辑前的url，修改后调回
        return $this->fetch('edit',['rows'=>$rows]);
    }

    public function save()
    {
        if($this->request->isAjax()){
            $m = new ProposeClassify();
            return $m->_save();
        }
    }

    //更新'0'或'1'
    public function flag($id)
    {
        if ($this->request->isAjax()) {
            $m = new ProposeClassify;     $data = input('post.');
            $res = $m->allowField(['is_show','is_top','is_index'])->save($data,['id'=>$id]); //失败返回false
            if($res !== false) $this->success('更新成功');
            else $this->error('请重试');
        }
    }
    //软删除
    public function delete($id = 0, $ids = [])
    {
        if($this->request->isAjax()){
            $id = $ids ? $ids : $id;
            $m = new ProposeClassify;
            return $m->_delete($id);
        }
    }
}